package com.ityueqiangu.project.exhibitionInfo.controller;


import cn.hutool.core.util.ObjectUtil;
import com.ityueqiangu.core.exception.BizException;
import com.ityueqiangu.core.web.controller.BaseController;
import com.ityueqiangu.core.constant.Constants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ityueqiangu.core.web.result.DataGridResultInfo;
import com.ityueqiangu.core.web.result.ResultDataUtil;
import com.ityueqiangu.core.web.result.ResultInfo;
import org.springframework.stereotype.Controller;
import com.ityueqiangu.core.enums.CommonEnum;
import java.util.List;
import com.ityueqiangu.project.exhibitionInfo.domain.ExhibitionInfo;
import com.ityueqiangu.project.exhibitionInfo.service.IExhibitionInfoService;

import javax.xml.transform.Result;

/**
 * @author Clever、xia
 * @title: ExhibitionInfoController
 * @description:
 * @date 2021-03-15 09:58:50
 */
@Controller
@RequestMapping(value = "/exhibitionInfo")
public class ExhibitionInfoController extends BaseController{

    @Autowired
    private IExhibitionInfoService exhibitionInfoService;
	/*访问路径前缀*/
    private final String PATH_PREFIX = "project/exhibitionInfo/";

	 /**
     * 访问主页
     * @return
     */
    @RequestMapping(value = "/index")
    public String index(){
        return PATH_PREFIX+"index";
    }

    /**
     * 新增
     * @return
     */
    @RequestMapping(value = "/add")
    public String add(){
        return PATH_PREFIX+"add";
    }

    /**
     * 修改
     * @return
     */
    @RequestMapping(value = "/edit")
    public String edit(){
        return PATH_PREFIX+"edit";
    }
	
    /**
     * 分页列表查询
     * @param exhibitionInfo
     * @return 返回DataGridResultInfo
     */
    @RequestMapping("/list")
    @ResponseBody
    public DataGridResultInfo list(ExhibitionInfo exhibitionInfo) {
    	startPage();
         //编写查询条件
        List<ExhibitionInfo> list = exhibitionInfoService.selectExhibitionInfoList(exhibitionInfo);
        return getDataTable(list);
    }


    /**
     * 根据主键查询
     *
     * @param exhibitionInfo
     * @return 返回ResultInfo
     */
    @RequestMapping("/selectExhibitionInfoById")
    @ResponseBody
    public ResultInfo selectExhibitionInfoById(ExhibitionInfo exhibitionInfo) {
    	ExhibitionInfo exhibitionInfoResult = exhibitionInfoService.selectExhibitionInfoById(exhibitionInfo.getId());
        return ResultDataUtil.createSuccess(CommonEnum.SELECT_SUCCESS).setData(exhibitionInfoResult);
    }
    
    /**
     * 新增
     *
     * @param exhibitionInfo 新增的记录
     * @return 返回ResultInfo
     */
    @RequestMapping("/save")
    @ResponseBody
    public ResultInfo save(ExhibitionInfo exhibitionInfo) {
        Integer result = exhibitionInfoService.insertExhibitionInfo(exhibitionInfo);
        if (result< Constants.ONE) {
            ResultDataUtil.createFail(CommonEnum.SAVE_FAILURE);
        }
        return ResultDataUtil.createSuccess(CommonEnum.SAVE_SUCCESS);
    }
    
    
    /**
     * 修改，
     *
     * @param exhibitionInfo 修改的记录
     * @return 返回ResultInfo
     */
    @RequestMapping("/update")
    @ResponseBody
    public ResultInfo update(ExhibitionInfo exhibitionInfo) {
    	Integer result = exhibitionInfoService.updateExhibitionInfo(exhibitionInfo);
        if (result< Constants.ONE) {
            ResultDataUtil.createFail(CommonEnum.UPDATE_FAILURE);
        }
        return ResultDataUtil.createSuccess(CommonEnum.UPDATE_SUCCESS);
    }
    
    /**
     * 删除
     *
     * @param exhibitionInfo 待删除的记录
     * @return 返回ResultInfo
     */
    @RequestMapping("/remove")
    @ResponseBody
    public ResultInfo remove(ExhibitionInfo exhibitionInfo) {
    	Integer result = exhibitionInfoService.deleteExhibitionInfoById(exhibitionInfo.getId());
        if (result< Constants.ONE) {
            ResultDataUtil.createFail(CommonEnum.DELETE_FAILURE);
        }
        return ResultDataUtil.createSuccess(CommonEnum.DELETE_SUCCESS);
    }

    @RequestMapping("/existExhibitionName")
    @ResponseBody
    public ResultInfo existExhibitionName(ExhibitionInfo exhibitionInfo){
        ExhibitionInfo result = exhibitionInfoService.existExhibitionName(exhibitionInfo);
        if (ObjectUtil.isNotNull(result)) {
            return ResultDataUtil.createFail(CommonEnum.DATA_EXIST);
        }
        return ResultDataUtil.createSuccess(CommonEnum.DATA_NOT_EXIST);
    }

    @RequestMapping(value = "/appoint")
    @ResponseBody
    public ResultInfo appoint(ExhibitionInfo exhibitionInfo){
        Integer appoint = exhibitionInfoService.appoint(exhibitionInfo);
        if (ObjectUtil.isNull(appoint)) {
            throw new BizException(CommonEnum.APPOINT_FAILURE);
        }
        return ResultDataUtil.createSuccess(CommonEnum.APPOINT_SUCCESS);
    }

}